/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.jgls.bi.dataprocess;

import java.util.ArrayList;
import java.util.Iterator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.sql.DataSource;

/**
 *
 * @author zz
 */
public class ThreadWorker extends Thread {

    DataProcessJdbcDao tsDao = new DataProcessJdbcDao();
    DPJDSale taskDaoSal = new DPJDSale();
    pcaDataJdbcDao taskDaoPc = new pcaDataJdbcDao();
    psgprcJdbcDao taskDaoPsgprc = new psgprcJdbcDao();
    DPJDSaleHour taskDaoSaleHour = new DPJDSaleHour();
    LotteryMxJdbcDao taskDaoLotteryMx = new LotteryMxJdbcDao();
    biStockJdbcDao taskDaoBiStock = new biStockJdbcDao();
    biUnsalableJdbcDao taskDaoBiUnsalable = new biUnsalableJdbcDao();
    biProvidBalanceJdbcDao taskDaoBiBal = new  biProvidBalanceJdbcDao();
    biUnsalableSymbolJdbcDao taskDaoBiUnsalableSymbol = new biUnsalableSymbolJdbcDao();
    biStockTobaccoJdbcDao taskDaoBiStockTobacco = new biStockTobaccoJdbcDao();
    biSaleYybHzJdbcDao taskDaoBiSaleYybHz = new biSaleYybHzJdbcDao();
    java.sql.Date ldDate;
    int iShopId, iDateNo, iYybh, iManId, iBj;
    String sShopBm, sYear, sTab;
    DataSource ds;
    ArrayList<String> fctName = new ArrayList<String>();
    int i;
    String ls_fname;
    Iterator ShopIter1;
    ArrayList<ArchiDept> lad = new ArrayList<ArchiDept>();

    ThreadWorker(ArrayList<ArchiDept> lArchiD) {
        lad = lArchiD;
    }

    public void setParam(java.sql.Date adTsnDate, int aiShopId, String asShopBm,
            int aiDateNo, String asYear, int aiYybh, int aiMan_id, String asTname) {
        this.ldDate = adTsnDate;
        this.iShopId = aiShopId;
        this.sShopBm = asShopBm;
        this.iDateNo = aiDateNo;
        this.sYear = asYear;
        this.iYybh = aiYybh;
        this.iManId = aiMan_id;
        this.sTab = asTname;
    }

    public void setParm(java.sql.Date adTsnDate, int aiDateNo, String asYear, String asTname, String asFname) {
        this.ldDate = adTsnDate;
        this.iDateNo = aiDateNo;
        this.sYear = asYear;
        this.sTab = asTname;
        this.ls_fname = asFname;
    }

    @Override
    public void run() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringConfig_Jdbc.xml");
        ds = (DataSource) ctx.getBean("dataSourceDBDirect");
        ArchiDept ad = new ArchiDept();
        for (i = 0; i < lad.size(); i++) {
            //while (ShopIter1.hasNext()) {
            ad = lad.get(i);
            iShopId = ad.getId();
            sShopBm = ad.getBm();
            iYybh = ad.getYybh();
            iManId = ad.getMan_id();
            //判断要调用哪个方法
            //1、A报表-交易笔数
            if (ls_fname.equalsIgnoreCase("tsnamt")) {
                tsDao.setDataSource(ds);
                tsDao.TsnAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //2、A报表-销售
            if (ls_fname.equalsIgnoreCase("saleamt")) {
                taskDaoSal.setDataSource(ds);
                taskDaoSal.SaleAmt(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //3、客品数 
            if (ls_fname.equalsIgnoreCase("pcadata")) {
                taskDaoPc.setDataSource(ds);
                taskDaoPc.pcaData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //4、客单价
            if (ls_fname.equalsIgnoreCase("psgprcdata")) {
                taskDaoPsgprc.setDataSource(ds);
                taskDaoPsgprc.psgprcData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //5、时段销售SaleAmtHour
            if (ls_fname.equalsIgnoreCase("saleamthour")) {
                taskDaoSaleHour.setDataSource(ds);
                taskDaoSaleHour.SaleAmtHour(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //6、彩票销售兑奖信息
            if (ls_fname.equalsIgnoreCase("lotterymx")) {
                taskDaoLotteryMx.setDataSource(ds);
                taskDaoLotteryMx.LotteryMxData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //7、每种商品当日的库存状况
            if (ls_fname.equalsIgnoreCase("bistock")) {
                taskDaoBiStock.setDataSource(ds);
                taskDaoBiStock.biStockData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //8、每种商品当日的库存店数、配置店数
            if (ls_fname.equalsIgnoreCase("biunsalable")) {
                taskDaoBiUnsalable.setDataSource(ds);
                taskDaoBiUnsalable.biUnsalableData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //9、每种商品当日的库存店数、配置店数
            if (ls_fname.equalsIgnoreCase("biprovidbalance")) {
                taskDaoBiBal.setDataSource(ds);
                taskDaoBiBal.biProvidBalanceData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //10、每种商品当日的库存店数、配置店数(9家试点门店)
            if (ls_fname.equalsIgnoreCase("biunsalablesymbol")) {
                taskDaoBiUnsalableSymbol.setDataSource(ds);
                taskDaoBiUnsalableSymbol.biUnsalableData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //11、每家门店烟草类商品库存情况
            if (ls_fname.equalsIgnoreCase("bistocktobacco")) {
                taskDaoBiStockTobacco.setDataSource(ds);
                taskDaoBiStockTobacco.biStockTobaccoData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            //12、每天生产按照营运部汇总的销售汇总-供外网的供货商查询使用
            if (ls_fname.equalsIgnoreCase("bisaleyybhz")) {
                taskDaoBiSaleYybHz.setDataSource(ds);
                taskDaoBiSaleYybHz.biSaleYybHzData(ldDate, iShopId, sShopBm, iDateNo, sYear, iYybh, iManId, sTab);
            }
            
            
        }
    }
}
